<!-- 添加收货地址 -->
<template>
	<view style="padding: 15px;">
		<form @submit="formSubmit">
			<view class="uni-common-mt">
				<view class="uni-form-item uni-column user-input">
					<view class="title">收货人</view>
					<view class="input">
						<input class="uni-input" name="userName" v-model="formData.userName" maxlength="10"
							placeholder="请输入收货人" />
					</view>
				</view>
				<view class="fenjie"></view>
				<view class="uni-form-item uni-column user-input">
					<view class="title">电话</view>
					<view class="input">
						<input class="uni-input" name="userPhone" v-model="formData.userPhone" maxlength="11"
							placeholder="请输入电话" />
					</view>
				</view>
				<view class="fenjie"></view>
				<view class="uni-form-item uni-column user-input">
					<view class="title">收货地址</view>
					<view class="input">
						<input class="uni-input" name="userAddress" v-model="formData.userAddress" maxlength="100"
							placeholder="请输入收货地址" />
					</view>
				</view>
				<view class="fenjie"></view>

			</view>
			<button style="margin-top: 10px;" form-type="submit">提交保存</button>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData: {
					userName: '',
					userPhone: '',
					userAddress: ''
				}
			}
		},
		onLoad() {

		},
		methods: {
			formSubmit(e) {
				let openid = uni.getStorageSync('openid')

				if (!this.formData.userName) {
					uni.showToast({
						title: '请输入收货人',
						icon: "none"
					});
					return
				}
				if (!this.formData.userPhone) {
					uni.showToast({
						title: '请输入电话',
						icon: "none"
					});
					return
				}
				if (!this.formData.userAddress) {
					uni.showToast({
						title: '请输入收货地址',
						icon: "none"
					});
					return
				}

				this.$app._get('entry/wxapp/goods.creatuseraddress', {
					openid: wx.getStorageSync("openid"),
					userName: this.formData.userName, //姓名
					userPhone: this.formData.userPhone, //电话
					userAddress: this.formData.userAddress // 地址
				}, (result) => {
					console.log(result)
					uni.navigateBack()
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.user-input {
		width: 335px;
		margin: 20px auto;
		display: flex;
	
		.title {
			width: 100px;
		}
	
		.input {
			width: 280px;
			margin-left: 20px;
		}
	}
	
	.fenjie {
		height: 1px;
		background: #ddd;
		margin: 0 auto;
	}
	
	.up-button {
		width: 100%;
		height: 40px;
		background: #0096FB;
		border-radius: 4px;
		font-size: 16px;
		line-height: 40px;
		color: white;
		margin-top: 30px;
	}
</style>